package com.jbp.controller;

import com.jbp.model.EquipRoom;
import com.jbp.model.Music;
import com.jbp.service.MusicService;
import com.jbp.utils.PageUtils;
import com.jbp.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.Map;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;

/**
 * (Music)表控制层
 * @author cc
 * @since 2020-10-14 10:42:04
 */
@Api(tags ="APP接口--Music" )
@RestController
@RequestMapping("rest/music")
public class MusicController {
    @Autowired
    private MusicService musicService;

    /** 列表 */
    @ApiOperation(value="列表",hidden = true)
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Music.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = musicService.queryPage(params);
        return R.ok().put("page", page);
    }
    /** 我的音乐 */
    @ApiOperation(value="我的音乐列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = Music.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @GetMapping("/myMusics")
    public R myMusics(@RequestParam Map<String, Object> params, @RequestAttribute("userId") Integer userId){
        params.put("userId",userId);
        PageUtils page = musicService.myMusics(params);
        return R.ok().put("page", page);
    }

    /** 喜欢音乐 */
    @ApiOperation(value="喜欢音乐",hidden = true)
    @GetMapping("/like")
    public R like(@RequestParam Integer musicId){
        musicService.like(musicId);
        return R.ok();
    }

    /** 保存 */
    @PostMapping("/save")
    @ApiOperation(value="保存")
    public R save(@RequestBody Music music){
        musicService.save(music);
        return R.ok();
    }

    /** 修改 */
    @RequestMapping("/update")
    @ApiOperation(value="修改",hidden = true)
    public R update(@RequestBody Music music){
        musicService.updateById(music);
        return R.ok();
    }

    /** 删除 */
    @PostMapping("/delete")
    @ApiOperation(value="删除")
    public R delete(@RequestBody Integer[] ids){
        musicService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
}